import 'package:flutter/material.dart';

import '../../../helper/utils/util.dart';
part 'item.dart';

class AppBottomBar extends StatelessWidget {
  const AppBottomBar({
    super.key,
    required this.children,
    this.currentIndex = 1,
    this.unSelectedColor = Colors.grey,
    this.selectedColor = Colors.blue,
    this.backgroundColor,
    this.onTap,
  });
  final List<AppTabbarItem> children;
  final Color? backgroundColor;
  final Color? unSelectedColor;
  final Color? selectedColor;
  final void Function(int)? onTap;
  final int currentIndex;
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Container(
        height: 58.r,
        decoration: BoxDecoration(
          color: backgroundColor,
          border: const Border(
              top: BorderSide(color: Color(0xffefefef), width: 0.5)),
        ),
        child: Row(
          children: children
              .asMap()
              .map(
                (i, item) => MapEntry(
                  i,
                  Expanded(
                    child: _AppTabbarItem(
                      item
                        ..color ??= unSelectedColor
                        ..activeColor ??= selectedColor,
                      isSelected: i == currentIndex,
                      onTap: () {
                        if (onTap != null) {
                          onTap!(i);
                        }
                      },
                    ),
                  ),
                ),
              )
              .values
              .toList(),
        ),
      ),
    );
  }
}
